 <template>
 	<view>
 		<!-- 手持机自带扫描 -->
 		<infraredCode></infraredCode>
 		<view class="uni-flex uni-column" style="height: 100%;">
 			<!-- #ifdef APP-PLUS -->
 			<view class="status_bar">
 				<view class="top_view"></view>
 			</view>
 			<!-- #endif -->
 			<view class="uni-flex uni-row jk-bg-blue uni-center"
 				style="height: 12%;text-align: center;font-size: 18px;" :style="{'margin-top':barHeight+'px'}">
 				标签打印
 			</view>
 			<view class="uni-flex align-center uni-row margin-xs" style="height: 88%;">
 				<search placeholder="订单号" :fixed="false" />
 			</view>
 		</view>
 	</view>
 </template>

 <script>
 	var _self;
 	import infraredCode from "@/components/infrared-code/index.vue";
 	const print = uni.requireNativePlugin('Sunmi-Print-Inner');
 	var isConnect = false;
 	export default {
 		components: {
 			infraredCode,
 		},
 		data() {
 			return {
 				lianjie: "",
 				barHeight: 25,
 			}
 		},
 		onLoad: function() {
 			_self = this;
 			_self.getSystemStatusBarHeight();
 			//首页监听PDA扫码数据
 			uni.$on('scancodedate', function(data) {
 				_self.searchList(data.code)
 			})
 		},
 		onUnload() {
 			// 移除监听事件      
 			uni.$off('scancodedate')
 		},
 		methods: {
 			//获取系统状态栏高度
 			getSystemStatusBarHeight: function() {
 				// #ifdef APP-PLUS
 				var height = plus.navigator.getStatusbarHeight();
 				_self.barHeight = height;
 				// #endif
 				// #ifdef H5
 				_self.barHeight = 0;
 				// #endif
 			},
 			searchList(e) {
 				this.start(e.split('=')[1])
 			},
 			start(e) {
 				let that = this
 				print.connect(res => {
 					isConnect = res.connect == "hello"
 					that.print(e); //打印
 				})
 			},
 			// 打印事件
 			print(e) {
 				if (isConnect) {
 					//打印小票
 					print.printQrCode({
 						text: e,
 						size: 6,
 						errorlevel: 0,
 						align: 1
 					})
 					//空白行分割之前打印内容（类似走空白）
 					print.printDividingline({
 						style: "4",
 						height: "10"
 					})
 					print.printText({
 						text: "订单号：" + e,
 						align: 1,
 						size: 26,
 						bold: true,
 					})
 					print.labelOutput()
 				}
 			},
 		}
 	}
 </script>

 <style>
 </style>